# Contributor: Holger Jaekel <holger.jaekel@gmx.de>
# Maintainer: Holger Jaekel <holger.jaekel@gmx.de>
pkgname=netcdf
pkgver=4.8.1
pkgrel=2
pkgdesc="Libraries for the Unidata network Common Data Format"
url="https://www.unidata.ucar.edu/software/netcdf/"
# disabled on s390x because of https://github.com/Unidata/netcdf-c/issues/1987
arch="all !s390x"
license="BSD-3-Clause"
options="net"  # tests need network access
makedepends="
	bash
	cmake
	curl-dev
	hdf5-dev
	libexecinfo-dev
	m4
	"
subpackages="
	$pkgname-doc
	$pkgname-dev
	$pkgname-utils:utils
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/Unidata/netcdf-c/archive/v$pkgver.tar.gz
	fix-test-on-big-endian.patch
	manyurls.patch::https://github.com/Unidata/netcdf-c/commit/f235dcfdb23072195b09543e3224d3ef3610fea8.patch
	"
builddir="$srcdir/$pkgname-c-$pkgver"

build() {
	local _enable_cdf5=ON
	case "$CARCH" in
		x86|armhf|armv7) _enable_cdf5=OFF ;;
	esac
	cmake . \
		-DCFLAGS="$CFLAGS" \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=None \
		-DENABLE_CDF5=$_enable_cdf5 \
		-DENABLE_DAP_LONG_TESTS=ON \
		-DENABLE_EXAMPLE_TESTS=ON \
		-DENABLE_EXTRA_TESTS=ON \
		-DENABLE_FAILING_TESTS=ON \
		-DENABLE_FILTER_TESTING=ON \
		-DENABLE_LARGE_FILE_TESTS=ON
	make
}

package() {
	make DESTDIR="$pkgdir" install
}

utils() {
	install -d "$subpkgdir/usr/bin"
	mv "$pkgdir/usr/bin" "$subpkgdir/usr/"
}

check() {
	# One test failure in nc_test as reported in https://github.com/Unidata/netcdf-c/issues/808
	# Server test.opendap.org:8080 seems to be down for dap4_test_test_hyrax test
	# Tests have to be executed in the correct order
	# ncdap_tst_remote3: fails repeatedly on builder
	ctest -j 1 -E 'nc_test|dap4_test_test_hyrax|ncdump_test_rcmerge|ncdap_tst_remote3'
}

sha512sums="
c97207867abf10d414abf34624268710f5b812c26c38f97e73afe00558b3f07917331fbc7fdb9e70b09813acf15a9a09bae2c432a3266ce10a791b9472f87a42  netcdf-4.8.1.tar.gz
29dda7a0e28333afb91f948c1f5527606634ab8014c6f123e73b092e550d9514c45391f11b33c59cbfbb1fd1ff581848305a47d3768f9b4d1a2be63609009d82  fix-test-on-big-endian.patch
c69e53c16a22c102f45a478091b28309fa584658c5d9a8ca4d8b47c03861caf4311b19b82425935cc3402c3e1c1c91a53ce4b78066faf5405fe744f040629078  manyurls.patch
"
